So I need to add a few things to my pistol, namely a kickback animation.
I need a cooldown and I need a muzzle flash because if we shoot doesn't look like it's doing anything.
Let's go ahead and get started with that.
So my simple pistol is in my starter pack.
We can leave it there.
I'll work on it right from the starter pack and I'm going to save this off because now that it's kind
of working, if I mess it up, I want to be able to get the old one back.
So I'm going to right click, I'm going to hit, let's see, Saved roadblocks.
And then you could put like version one here.
I actually have a version one.
I'm just demoing this, so I'm going to do overwrite an existing asset.
Click that, there's my version one.
I'm just going to overwrite that.
Submit.
But if you don't have one, you can just hit the submit on that first window.
All righty.
Now let's open our simple pistol and hit the plus sign and add a configuration.
Right.
This is actually a folder.
We're going to put stuff on here that we can use to configure our pistol.
We're going to put the damage in there.
We're going to put the cool down.
We're going to put how much ammo we have.
But right now we're just going to work on cool down.
So hit that plus sign and then we're going to add a number value.
There it is.
Let's go ahead and write.
Cool down.
And we'll go down here to the value and make the cool down one second.
But we can make it like 1.5.
That's why I use a number value rather than an int value.
I.
So now let's go to our shoot script.
Open that up.
And I want to get a reference to my configuration folder.
Let's say local.
We'll call it config.
And we have a gun variable here.
Wait for child configuration.
There we go.
We got that.
I'll do another variable for cool down and that's in config.
So let's get our config variable.
We'll do a wait for child.
Cool down.
I need another variable for my D bounce.
So a D bounce is something that prevents software from firing too much.
It's actually used in digital electronics too, but I don't want to get into that.
Let's call this can shoot.
So this is going to prevent us from shooting during the cool down.
It's going to be a boolean.
We'll initialize it to true so we can shoot right away when we get the gun.
But then we got to wait after we fire it.
So I'm going to go down to on activated.
That's where we do our firing when we click on something.
I'm going to do a check.
If can shoot, then I will shoot.
I will send my stuff to the server because the shoot is a client, a client script.
All right.
But that's not sufficient.
It's going to keep shooting.
What we need to do is as soon as we shoot, we're going to set it to false.
We're going to set this to false.
And this statement will not fire until we turn it back.
So I will wait.
After I do my shoot, I'm going to get my cool down.
There it is.
Now, remember, this is an int value.
So we have to do the value or a number of values.
A number of value.
We still have to do the value and then I'll do a can shoot equals after we wait.
True.
So we will shoot because this is true when we first start out, then becomes false.
We fire to the server that does the bang and the damage.
Then we wait for our cool down and we can't shoot again until we get past our cool down.
That's pretty cool.
Let's go ahead and try it out.
Or we're in our world.
Pull out the pistol and I'm spamming
and spamming the click so you can see that it shoots about once a second, right?
That's the cooldown.
Now I'm going to do one more thing for the purist, because sometimes people say, Well, the shoot
script is a local script, which means it can be modified on the client, and if somebody really knows
what they're doing, then they can make their game more powerful.
So if you really want to be careful, let's go ahead and copy these.
Now go and open up your damaged script.
And we're going to paste the same variables.
There we go.
And this we don't have gun on this side, so I need to do a script parent.
And we've got our configuration, our cool down and can shoot.
Now let's go down to on shoot.
Now we'll do an if statement.
If I can shoot then.
You know, bring this down here to the bottom and.
I need to format.
Cool.
Can shoot will become false as soon as we shoot.
And then we'll go down to the bottom after we do the shooting.
Yes.
Right here gets a little tricky when you get a lot of ifs and ends.
We'll do our weight, right?
Weight.
We have our cool down.
And cool down is a number value.
I guarantee you you're going to forget this at least a couple of times in your programming.
We all do.
You get used to it, though.
And then after we weight can shoot will be true.
So essentially, we're doing the exact same thing on the server side.
The remote event is going to fire.
There might be like a little millisecond delay, but it's going to be pretty quick.
Remote events are asynchronous calls, so the lineup's not going to be perfect, but better than what
a user can can tell.
So you're just adding some strength here.
If you didn't have this code, you wouldn't notice unless someone tried to hack your hack your game.
All right, So now let's try it.
Make sure everything's good.
I think.
Let's look at our view output.
Yeah, no problem.
Now, all the other configuration stuff like damage and ammo, we're going to only be server side,
but we needed to have the DH balance for the cooldown on the client side because now we're going to
add a kickback animation.